package com.ldwx.center.service.impl;

import com.ldwx.center.dao.JobDao;
import com.ldwx.center.model.Job;
import com.ldwx.center.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class JobServiceImpl implements JobService{
    @Autowired
    private JobDao jobDao;

    @Override
    public void addJob(Job job) {
        jobDao.save(job);
    }

    @Override
    public Job findJobByName(String name) {
        Job addJob = new Job();
        addJob.setJobName(name);
        Example<Job> example = Example.of(addJob);
        Optional<Job> optionalJob  = jobDao.findOne(example);
        Job resultJob = null;
        if(optionalJob.isPresent()){
            resultJob = optionalJob.get();
        }
        return resultJob;
    }
}
